local skel = fk.CreateSkill {
  name = "emo__beiai",
}

skel:addEffect(fk.TurnStart, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target ~= player and not target.dead
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askToSkillInvoke(target, {skill_name = skel.name, prompt = "#emo__beiai-invoke:"..player.id }) then
      event:setCostData(self, {tos = {target}})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    player.room:addTableMark(target, "@@emo__beiai", player.id)
  end,
})

skel:addEffect(fk.HpRecover, {
  is_delay_effect = true,
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return target and target ~= player and not player.dead and player:isWounded()
    and table.contains(target:getTableMark("@@emo__beiai"), player.id)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player.room:recover { num = data.num, skillName = skel.name, who = player, recoverBy = player }
  end,
})

skel:addEffect(fk.AfterCardTargetDeclared, {
  is_delay_effect = true,
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    if target and target ~= player and not player.dead and table.contains(target:getTableMark("@@emo__beiai"), player.id) then
      return (data.card:isCommonTrick() or data.card.type == Card.TypeBasic)
      and table.contains(data.tos, target) and table.contains(data:getExtraTargets(), player)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    data:addTarget(player)
  end,
})

-- 目标回合开始时清理标记
skel:addEffect(fk.TurnStart, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@@emo__beiai") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@emo__beiai", 0)
  end,
})

-- 自己死亡时清理所有给别人加的标记
skel:addLoseEffect(function (self, player, is_death)
  for _, p in ipairs(player.room.alive_players) do
    player.room:removeTableMark(p, "@@emo__beiai", player.id)
  end
end)

Fk:loadTranslationTable{
  ["emo__beiai"] = "被爱",
  [":emo__beiai"] = "其他角色的回合开始时，其可以获得以下效果直到其下回合开始时：当其回复体力时，你回复等量体力，其对自己使用牌增加你为额外目标。",

  ["#emo__beiai-invoke"] = "被爱：你可以令你回复体力时，让 %src 也回复等量，且你对自己用牌也会对其使用",
  ["@@emo__beiai"] = "被爱",
}

return skel
